//
//  HomePageHeader.m
//  ZhiHuDaily
//
//  Created by 吴宜昊 on 2022/2/5.
//

#import "HomePageHeader.h"

@interface HomePageHeader ()
@property(nonatomic,strong) SDCycleScrollView * cycleScrollView;
@property(nonatomic,weak) id <SDCycleScrollViewDelegate> delegate;
@end
@implementation HomePageHeader

#pragma mark - override
-(instancetype) initWithFrame:(CGRect) frame delegate:(id <SDCycleScrollViewDelegate> ) delegate {
    self = [super initWithFrame:frame];
    if (self) {
        self.delegate = delegate;
        [self setupUI];
    }
    return self;
}

-(void) updateConstraints {
    [self remakeMas];
    [super updateConstraints];
}

#pragma mark - remakeMas
-(void) remakeMas {
    [self.cycleScrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets( UIEdgeInsetsZero );
    }];
}

#pragma mark - override
-(void) setupUI {
    [self addSubview:self.cycleScrollView];
    [self setNeedsUpdateConstraints];
}

#pragma mark - lazy
-(SDCycleScrollView *) cycleScrollView {
    if (!_cycleScrollView) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:self.bounds delegate:self.delegate placeholderImage:ImageDefault];
        
        _cycleScrollView.autoScrollTimeInterval = 1.0;
        _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
        _cycleScrollView.showPageControl = YES;
        _cycleScrollView.currentPageDotColor = UIColor.redColor;
        _cycleScrollView.pageDotColor = UIColor.lightGrayColor;
        _cycleScrollView.pageControlDotSize = CGSizeMake(70, 20);
        
        _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        _cycleScrollView.titleLabelHeight = 44;
    }
    return _cycleScrollView;
}

#pragma mark - reload
-(void) reloadBanner:(NSArray *) urls titles:(NSArray *) titles {
    _cycleScrollView.titlesGroup = titles;
    _cycleScrollView.imageURLStringsGroup = urls;
}

@end
